//参考资料
//C++ 多线程编程实战
#include <iostream>

using namespace std;

// 实现两个复数的加法运算
// 通过传引用的方式实现返回两个值
void ComplexAdd(double dReal1, double dImg1, double dReal2, double dImg2, double &dReal, double &dImg)
{
	dReal = dReal1 + dReal2;
	dImg = dImg1 + dImg2;
}

// 在指定范围内生成一个随机数
double Rand(double dMin, double dMax)
{
	double dVal = (double)rand() / RAND_MAX;
	return dMin + dVal * (dMax - dMin);
}

int main(int argc, char *argv[])
{
	double dReal1 = Rand(-10, 10);
	double dImg1 = Rand(-10, 10);
	double dReal2 = Rand(-10, 10);
	double dImg2 = Rand(-10, 10);

	double dReal = 0;
	double dImg = 0;

	ComplexAdd(dReal1, dImg1, dReal2, dImg2, dReal, dImg);

	cout << dReal << "+" << dImg << "i" << endl;
	return 0;
}